package com.cc.visitor.config;

import com.cc.alltype.BusinessException;
import com.cc.visitor.dao.UserWeixinMapper;
import com.cc.visitor.entity.UserWeixin;
import com.mybatisflex.annotation.InsertListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Optional;

/**
 * @author chanchaw
 * @create 2024-09-19 8:21
 */
public class InsertListenerUserWeixin implements InsertListener {
    private UserWeixinMapper dao;
    private static final Logger logger = LoggerFactory.getLogger("userWeixin");
    private static final String LOG_ISNULL = "新增微信用户时传入的对象是NULL，无法新增";
    private static final String LOG_ILLEGAL_OPEN_ID = "非法的 openId";
    @Override
    public void onInsert(Object o) {
        if(o == null){
            logger.info(LOG_ISNULL);
            throw new BusinessException(LOG_ISNULL);
        }
//        UserWeixin record = (UserWeixin)o;
//        checkData(record);

    }

    private void checkData(UserWeixin record){
        String openId = Optional.ofNullable(record.getOpenId()).orElse("");
        if(openId.length() == 0){
            logger.info(LOG_ILLEGAL_OPEN_ID);
            throw new BusinessException(LOG_ILLEGAL_OPEN_ID);
        }
    }
}
